package homework;
import java.util.Arrays;
public class Employee {private int id;
    private String name;
    private double salary;
    private Employee[] employees;
    public Employee(int id, String name, double salary) {
        this.id = id;
        this.name = name;
        this.salary = salary;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public double getSalary() {
        return salary;
    }
    public void setSalary(double salary) {
        this.salary = salary;
    }
    public Employee[] getEmployees() {
        return employees;
    }
    public void setEmployees(Employee[] employees) {
        this.employees = employees;
    }
    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Employee{");
        sb.append("id=").append(id);
        sb.append(", name='").append(name).append('\'');
        sb.append(", salary=").append(salary);
        sb.append('}');
        return sb.toString();
    }
    public void addEmp(Employee employee){
        // boss.setEmployees(new Employee[0]);
        if(null==employees){
            System.out.println("sorry,您没有权限添加!");
            return;
        }
        employees = Arrays.copyOf(employees,employees.length+1);
        employees[employees.length-1]=employee;
    }
    public void findAll(){
        if(null!=employees && employees.length>0){
            for (Employee employee : employees) {
                System.out.println(employee);
            }
        }else{
            System.out.println("sorry,请先添加下属!");
        }
    }
    public void delById(int id) {
        for (int i = 0; i < employees.length; i++) {
            if (id == employees[i].getId()) {
                for(int j=i;j<employees.length-1;j++){
                    employees[j]=employees[j+1];
                }
                employees = Arrays.copyOf(employees,employees.length-1);
            }
        }
    }
    public void delByPrice(double price) {
        for (int i = 0; i < employees.length; i++) {
            if (price>employees[i] .getSalary()) {
                for (int j = i; j < employees.length - 1; j++) {
                    employees[j] = employees[j + 1];
                }
                employees = Arrays.copyOf(employees,employees.length-1);
            }
        }
    }
}
